package com.hxexp.weixin.common.jaxb;

import java.io.Reader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

/**
 * XML转换Java对象助手类
 *
 * @author li.jiang
 *
 */
public final class JaxbUnmarshallerHelper {
    private JaxbUnmarshallerHelper() {
    }

    /**
     * xml转换成对象
     *
     * @param reader
     *            字符读入reader
     * @return 转换成功的对象
     * @throws JAXBException
     */
    public static Object unmarshal(Reader reader, Class<?>[] jaxbClasses) throws JAXBException {
        JAXBContext context = JAXBContext.newInstance(jaxbClasses);

        Unmarshaller unmarshaller = context.createUnmarshaller();
        return unmarshaller.unmarshal(reader);
    }
}
